﻿@model Sharp.WebBooter.Areas.CMS.Models.VIUReViewViewModel
@{
    Layout = null;
}


<section class="content">
    <div class="row">
        <div class="col-md-7">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">内容预览</h3>

                    <div class="box-tools pull-right">
                        <a href="#" class="btn btn-box-tool" data-toggle="tooltip" title="上一篇"><i class="fa fa-chevron-left"></i></a>
                        <a href="#" class="btn btn-box-tool" data-toggle="tooltip" title="下一篇"><i class="fa fa-chevron-right"></i></a>
                    </div>
                </div>
                <div class="box-body no-padding">
                    <div class="mailbox-read-info">
                        <h3>
                            <span class="badge" data-bind="text:category.name">@Model.Category.Name</span> @Model.Title
                        </h3>
                        <h6>
                            编辑: @Model.EditorName
                            <span class="pull-right"><i class="fa fa-calendar"></i> @Model.CheckInTime</span>
                        </h6>

                    </div>
                    <div class="mailbox-controls with-border text-center clearfix">

                        <label class="pull-left">所属领域：</label>
                        <ul class="list-inline pull-left">

                            @foreach (var item in Model.Fields)
                            {
                                <li>
                                    <label class="label bg-red">@item.Name</label>
                                </li>
                            }
                        </ul>

                    </div>
                    <div class="mailbox-read-message" style="min-height: 150px;">
                        @MvcHtmlString.Create(Model.Content)
                    </div>
                </div>
                <div class="box-footer">
                    <ul class="mailbox-attachments clearfix">
                        @foreach (var item in Model.MultiMedias)
                        {
                            <li style="border: 0px; width: 162px;">
                                <div class="thumbnail">
                                    <img draggable="false" src="@item.ThumbUrl" alt="图片附件">
                                </div>
                            </li>
                        }
                    </ul>
                </div>
                <div class="box-footer">
                    <label class="pull-left ">TAGs：</label>
                    <ul class="list-inline pull-left">
                        @foreach (var item in Model.Tags)
                        {
                            <li>
                                <label class="label bg-red">@item.Name</label>
                            </li>
                        }
                    </ul>
                </div>
            </div>
        </div>
        <div class="col-md-5">
            <div class="btn-group">
                <a href="javascript:window.app.loadUI('/VIU/Index');" class="btn btn-default"><i class="fa fa-backward"></i> 返回VIU</a>
                <a href="javascript:window.app.loadUI('/VIU/Review/@Model.Id');" class="btn btn-default"><i class="fa fa-refresh"></i> 刷新VIU</a>
                <a href="javascript:void(0)" onclick="$('#history').modal('show');" class="btn btn-default"><i class="fa fa-history"></i> 审核历史 <span class="badge">@Model.ApproveHistories.Count</span></a>
            </div>
            @if (Model.IsChecked)
            {
                <div class='callout callout-info'>
                    <h4>
                        <i class='fa fa-info'></i> 注意:
                    </h4>这篇VIU已经审核。
                </div>
            }
            @if (Model.ApproveHistories.Any() && Model.ApproveHistories.All(x => x.CheckInTime < Model.CheckInTime))
            {
                <div class='callout callout-info'>
                    <h4>
                        <i class='fa fa-info'></i> 注意:
                    </h4>这篇VIU审核后有修改。
                </div>
            }
            <div class='box box-solid'>
                <div class="box-header with-border">
                    <h3 class="box-title">审核信息</h3>
                </div>
                <div class="box-body no-padding" id="reviewForm">

                    @using (Html.Bootstrap().BeginForm(c => c.Horizontal()))
                    {
                        <div class="form-group">
                            <label class="col-sm-3 control-label">是否通过</label>
                            <div class="col-sm-9">
                                <label><input type="radio" name="IsChecked" value="true" /> 通过</label>
                                <label><input type="radio" name="IsChecked" value="false" /> 不通过</label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">审批意见</label>
                            <div class="col-sm-9">
                                <textarea name="Remark" class="form-control"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-3 col-sm-9">
                                <button type="button" onclick="SaveReview()" class="btn btn-default">确定</button>
                            </div>
                        </div>
                        <input type="hidden" name="VIUId" value="@Model.Id" />
                    }
                </div>
            </div>


        </div>
    </div>
</section>
<div class="modal fade " aria-hidden="true" id="history">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span></button>
                <h4 class="modal-title" id="myModalLabel">审核历史</h4>
            </div>
            <div class="modal-body">
                <table class="table table-bordered table-striped" role="grid" aria-describedby="example_info" style="width: 100%;">
                    <thead>
                        <tr role="row">
                            <th class="center" rowspan="1" colspan="1" style="width: 100px;">是否通过</th>
                            <th class="left" rowspan="1" colspan="1" style="width: 100px;">审核人</th>
                            <th class="left" rowspan="1" colspan="1">审核意见</th>
                            <th class="center" rowspan="1" colspan="1" style="width: 120px;">日期</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model.ApproveHistories)
                        {
                            <tr role="row" class="odd @(item.IsChecked?"":"danger")">
                                <td class="center">@(item.IsChecked ? "通过" : "未通过")</td>
                                <td class="left">@item.ApproverName</td>
                                <td class="left">@item.Remark</td>
                                <td class="center">@item.CheckInTime.Value.ToString("MM-dd HH:mm:ss")</td>
                            </tr>
                        }
                        @if (Model.ApproveHistories.Count == 0)
                        {
                            <tr role="row" class="odd">
                                <td class="left" colspan="3">无审核历史</td>
                            </tr>
                        }
                    </tbody>
                </table>

            </div>
        </div>
    </div>
</div>
<script>
    function SaveReview() {
        $.ajax({
            type: "POST",
            url: "/VIU/SaveReview",
            data: $("#reviewForm form").serialize(),
            dataType: "json",
            success: function (data) {
                if (data.Err.length > 0) {
                    swal("出错啦！", data.Err, "error");
                }
                else {
                    window.app.loadUI("/VIU/Index");
                }
            },
            error: function (xmlHttpRequest, textStatus, errorThrown) {
                window.app.message("服务器异常。" + textStatus);
            }
        });
    }
</script>